package com.qdsg.ysg.doctor.ui;

import android.os.Bundle;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qdsg.ysg.doctor.util.ImageLoaderHelper;
import com.qdsg.ysg.doctor.util.ToastUtil;
import com.qdsg.ysg.doctor.util.UIConstants;
import com.rest.business.RestProxy;
import com.rest.response.DiagnoseOrderDetailResponse;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

import com.qdsg.ysg.doctor.R;
import com.qdsg.ysg.doctor.base.BaseActivity;

public class DiagnoseOrderDetailActivity extends BaseActivity {

    @BindView(R.id.title)
    RelativeLayout title;
    @BindView(R.id.img_head)
    ImageView imgHead;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_level)
    TextView tvLevel;
    @BindView(R.id.tv_recipel)
    TextView tvRecipel;
    @BindView(R.id.tv_consult_type)
    TextView tvConsultType;
    @BindView(R.id.tv_deptName)
    TextView tvDeptName;
    @BindView(R.id.tv_detail)
    TextView tvDetail;
    @BindView(R.id.tv_oneselfState)
    TextView tvOneselfState;
    @BindView(R.id.tv_main)
    TextView tvMain;
    @BindView(R.id.tv_advice)
    TextView tvAdvice;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.ratingBar)
    RatingBar ratingBar;
    String diagnoseId, orderId;
    int canChat;

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {
        diagnoseId = getIntent().getStringExtra("diagnoseId");
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.aty_diagnose_order_detail;
    }

    @Override
    protected void onResume() {
        super.onResume();
        diagnoseOrderDetail();
    }

    @OnClick(R.id.chat_container)
    void chat_container() {
        if (canChat == 1) {
            Bundle bundle = new Bundle();
            bundle.putSerializable("diagnoseId", diagnoseId);
            startActivity(ChatActivity.class, bundle);
        } else {
            ToastUtil.showToastCenter( mContext, "暂无聊天记录" );
        }
    }


    public void diagnoseOrderDetail() {
        RestProxy.getInstance().diagnoseOrderDetail(diagnoseId, new Observer<DiagnoseOrderDetailResponse>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(DiagnoseOrderDetailResponse diagnoseOrderDetailResponse) {
                ImageLoaderHelper.getInstance().GlideImageLoader(DiagnoseOrderDetailActivity.this, diagnoseOrderDetailResponse.data.avatar, imgHead, R.mipmap.img_default);
                tvName.setText(diagnoseOrderDetailResponse.data.docName);
                if (diagnoseOrderDetailResponse.data.isPrescription == 0) {
                    tvRecipel.setText("非处方");
                } else {
                    tvRecipel.setText("处方");
                }

                if (diagnoseOrderDetailResponse.data.businessType == UIConstants.GRAPHIC_TYPE_1){
                    tvConsultType.setText(R.string.string_consult);
                    tvConsultType.setBackgroundColor(getResources().getColor(R.color.color_grey_button_normal));

                }else if (diagnoseOrderDetailResponse.data.businessType == UIConstants.GRAPHIC_TYPE_2){
                    tvConsultType.setText(R.string.string_referral);
                    tvConsultType.setBackgroundColor(getResources().getColor(R.color.chooser_orange));
                }


                tvDeptName.setText(diagnoseOrderDetailResponse.data.deptName);
                tvLevel.setText(diagnoseOrderDetailResponse.data.docJobTitle);
                tvDetail.setText(diagnoseOrderDetailResponse.data.patientInfo);
                tvOneselfState.setText(diagnoseOrderDetailResponse.data.descriptionInfo);
                tvMain.setText(diagnoseOrderDetailResponse.data.mainDiagnosis);
                tvAdvice.setText(diagnoseOrderDetailResponse.data.docProposal);
                tvTime.setText(diagnoseOrderDetailResponse.data.endTime);
                if (!TextUtils.isEmpty(diagnoseOrderDetailResponse.data.score)) {
                    ratingBar.setRating(Float.parseFloat(diagnoseOrderDetailResponse.data.score));
                }
                orderId = diagnoseOrderDetailResponse.data.orderId;
                canChat = diagnoseOrderDetailResponse.data.canChat;
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }

}
